package neuroBot.exploit.fulltilt;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import pokerLogic2.Util;

/** liest die bisherige hh aus dem chat-window von fulltilt aus **/
public class ChatWinReader {

	protected Robot rob;

	public ChatWinReader() {
		try {
			rob = new Robot();
			rob.setAutoWaitForIdle(true);
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}

	public String readChatWin(int time) {
		/** clipboard auslesen **/
		Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
		String data = null;
		for (int i = 0; data == null; i++) {
			chatWinToClipBoard(time);
			Util.sleep(100);
			try {
				Transferable transfer = sysClip.getContents(null);
				data = (String) transfer
						.getTransferData(DataFlavor.stringFlavor);
			} catch (Exception e) {
				e.printStackTrace();
				System.out.println("Clipboard-Error");
			}
			if ((i + 1) % 10 == 0)
				Util.sleep(4000);
		}
		return data;
	}

	protected void chatWinToClipBoard(int i) {
		/** letzte zeilen in clipboard kopieren **/
		/** letzte zeile anclicken **/
		rob.mouseMove(75, 560);
		rob.mousePress(InputEvent.BUTTON1_MASK);
		rob.mouseRelease(InputEvent.BUTTON1_MASK);
		/** chattext ans ende spulen **/
		rob.keyPress(KeyEvent.VK_END);
		rob.keyRelease(KeyEvent.VK_END);
		/** letzte zeilen markieren **/
		rob.mousePress(InputEvent.BUTTON1_MASK);

		for (int t = 0; t < 250 + i*2; t++) {
			rob.mouseMove(75, 560 - t);
		}

		rob.mouseRelease(InputEvent.BUTTON1_MASK);
		/** mit rechtsclick in clipboard kopieren **/
		rob.mouseMove(75, 560);
		rob.mousePress(InputEvent.BUTTON3_MASK);
		rob.mouseRelease(InputEvent.BUTTON3_MASK);
		Util.sleep(100);
		rob.mouseMove(95, 589);
		Util.sleep(100);
		rob.mousePress(InputEvent.BUTTON1_MASK);
		Util.sleep(100);
		rob.mouseRelease(InputEvent.BUTTON1_MASK);
	}
}
